//
//  SEGTrackTextView.m
//  Uhomebk
//
//  Created by mac on 2017/10/24.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "SEGTrackTextView.h"

@implementation SEGTrackTextView
-(instancetype)initWithFrame:(CGRect)frame dict:(NSDictionary *)dict
{
    if (self = [super initWithFrame:frame]) {
        [self setupUIWithFrame:frame dict:dict];
        
    }
    return self;
}

/**
 UI布局
 
 @param dict  dict
 */
-(void)setupUIWithFrame:(CGRect)frame dict:(NSDictionary *)dict
{
    NSString *titleStr = dict[@"title"];
    NSString *contentStr = dict[@"attrValue"];
    /* 标题*/
    titleStr = [NSString stringWithFormat:@"%@:",titleStr];
    CGSize titleSize = STRING_SIZE_FONT(200, titleStr, 15);
    UILabel *titleLbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 12, titleSize.width, ceil(titleSize.height))];
    titleLbl.font = kFont_15;
    titleLbl.numberOfLines = 0;
    [titleLbl setTextColor:kColor_1];
    titleLbl.text = titleStr;
    [self addSubview:titleLbl];
    
    /* 内容*/
    UILabel *cotentLbl = [[UILabel alloc] init];
    cotentLbl.numberOfLines = 0;
    cotentLbl.font = kFont_15;
    [cotentLbl setTextColor:kColor_1];
    [cotentLbl extendAttributedString:contentStr lineSpace:6 font:kFont_15 color:kColor_1 lineBreakMode:NSLineBreakByTruncatingTail];
    CGFloat contentWidth = self.width-CGRectGetMaxX(titleLbl.frame)-20;
    CGSize contentSize = [cotentLbl textRectForBounds:CGRectMake(0, 0, contentWidth, LYScreenHeight()) limitedToNumberOfLines:0].size;
    cotentLbl.frame = CGRectMake(CGRectGetMaxX(titleLbl.frame)+5, 12, contentWidth, contentSize.height);
    [self addSubview:cotentLbl];
    
    self.height = CGRectGetMaxY(cotentLbl.frame);
}


@end
